<?php
/*
 * Created on Nov 27, 2010
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
require_once 'ppsdk_include_path.inc';

require_once 'PayPal.php';
require_once 'PayPal/Profile/Handler/Array.php';
require_once 'PayPal/Profile/API.php';
require_once 'paypal-sdk/Log.php';

require_once 'constants.inc.php';
require_once 'SampleLogger.php';

class PaymentPro
{
	private $logger;
	private $paymentMethod;

	public function PaymentPro()
	{
		$this->logger = new SampleLogger('PaymentPro.php', PEAR_LOG_DEBUG);
	}
	
	public function getPaypalURL()
	{
		$paypalURL = '';
		if(ENVIRONMENT == 'live') {
			$paypalURL = 'https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=';
		} else {
			$paypalURL = 'https://www.' . ENVIRONMENT . '.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=';
		}
		
		return $paypalURL;
	}
	
	public function profile3Tokens($subject = null, $usename, $password, $signature, $environment)
	{
		$handler =& ProfileHandler_Array::getInstance(array(
        	'username' => $usename,
        	'environment' => $environment,
        	'certificateFile' => null,
        	'subject' => null,
     	 ));
     	 
     	$pid = ProfileHandler::generateID();
   
		$profile = & new APIProfile($pid, $handler);
		
		$profile->setAPIUsername($usename);
		$profile->setAPIPassword($password);
		$profile->setSignature($signature);
		$profile->setSubject($subject);
		$profile->setEnvironment($environment); 
		
		
		$this->logger->_log('Profile: '. print_r($profile, true));
    	
    	return $profile;
	}
	
	public function sessionStart3Tokens($subject = null, $usename = API_USER_NAME, $password = API_PASSWORD, $signature = SIGNATURE, $environment = ENVIRONMENT)
	{
		$profile = $this->profile3Tokens($subject, $usename, $password, $signature, $environment);
		
		$caller =& PayPal::getCallerServices($profile);
   		
   		return $profile;
	}
	
	public function markCardNumber($cardNumber)
	{
		if(empty($cardNumber))
			return '';
			
		return substr($cardNumber, 0, 4) . str_repeat('X', (strlen($cardNumber) - 8)) . substr($cardNumber, -4);

	}


}

?>
